﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using DZPK.SocketImpl;

namespace ParseMessageSequence
{
    class MessagePacket
    {
        public string SrcIP;
        public string DestIP;
        public ByteArray Data;

        public MessagePacket()
        {
            Data = new ByteArray();
        }
    }

    class PersionInfo
    {
        public int seatID;
        public Int64 seatMoney;
        public Int64 seatChips;
        public Int64 usrCoins;

        public PersionInfo()
        {
            seatID = 0;
            seatMoney = 0;
            seatChips = 0;
            usrCoins = 0;
        }
    }

    class FinalRound
    {
        public int seatID;
        public Int64 money;
        public int card1;
        public int cardv1;
        public int cardc1;
        public int card2;
        public int cardv2;
        public int cardc2;
        public int type;
        public int goodcard1;
        public int goodcardv1;
        public int goodcardc1;
        public int goodcard2;
        public int goodcardv2;
        public int goodcardc2;
        public int goodcard3;
        public int goodcardv3;
        public int goodcardc3;
        public int goodcard4;
        public int goodcardv4;
        public int goodcardc4;
        public int goodcard5;
        public int goodcardv5;
        public int goodcardc5;

        public FinalRound()
        { }
    }

    class Program
    {
        public static List<MessagePacket> listMessage = new List<MessagePacket>();
        public static ByteArray m_SendByteMap = new ByteArray();
        public static ByteArray m_RecvByteMap = new ByteArray();

        public static int CharToInt(char c)
        {
            int ret = -1;

            if (c >= '0' && c <= '9')
            {
                ret = c - '0';
            }
            else if (c >= 'a' && c <= 'f')
            {
                ret = c - 'a' + 10;
            }
            else 
            {
                throw new Exception("data error!");
            }

            return ret;
        }

        public static string IntCmdToString(int cmd)
        {
            string ret = string.Empty;

            switch (cmd)
            {
                case 16416:
                    ret = "SERVER_COMMAND_VOTEKICKUSER";
                    break;
                case 4098:
                    ret = "CLIENT_COMMAND_LOGOUT";
                    break;
                case 16391:
                    ret = "SERVER_BROADCAST_USER_STAND";
                    break;
                case 16408:
                    ret = "SERVER_COMMAND_USER_KICK";
                    break;
                case 16406:
                    ret = "SERVER_COMMAND_USER_FROMTOALLCHIPS";
                    break;
                case 16426:
                    ret = "SERVER_COMMAND_SNGUSERSTANDINFO";
                    break;
                case 16407:
                    ret = "SERVER_COMMAND_USER_NOTICEALL";
                    break;
                case 16429:
                    ret = "SERVER_COMMAND_SNGALLLOGIN_SUCCESS";
                    break;
                case 28673:
                    ret = "SERVER_DETECT_CONN";
                    break;
                case 16431:
                    ret = "SERVER_COMMAND_USERLOGIN";
                    break;
                case 4109:
                    ret = "CLIENT_COMMAND_USER_VOTEKICKUSER";
                    break;
                case 16397:
                    ret = "SERVER_COMMAND_DEAL_RIVER";
                    break;
                case 16441:
                    ret = "SERVER_COMMAND_MTTSNGUSEROVERINFO";
                    break;
                case 0x0101:
                    ret = "CLIENT_COMMAND_CONNECTSUCCEED";
                    break;
                case 4104:
                    ret = "CLIENT_COMMAND_USER_FROMTOALLCHIPS";
                    break;
                case 16449:
                    ret = "SERVER_AND_CLIENT_MAX_COMMAND";
                    break;
                case 4106:
                    ret = "CLIENT_COMMAND_USER_STAND";
                    break;
                case 16428:
                    ret = "SERVER_COMMAND_SNGUSERRANKINFO";
                    break;
                case 16413:
                    ret = "SERVER_COMMAND_LOGINOUT_SUCCESS";
                    break;
                case 12289:
                    ret = "SERVER_USERCHIPIN_ERR";
                    break;
                case 4101:
                    ret = "CLIENT_COMMAND_CHIPIN";
                    break;
                case 4108:
                    ret = "CLIENT_COMMAND_USER_ADDFRIEND_SUCCESS";
                    break;
                case 16398:
                    ret = "SERVER_COMMAND_START_CHIPIN";
                    break;
                case 4113:
                    ret = "CLIENT_COMMAND_LOTTERYBUY";
                    break;
                case 16432:
                    ret = "SERVER_COMMAND_USERLOGOUT";
                    break;
                case 4116:
                    ret = "CLIENT_COMMAND_CONTINUE";
                    break;
                case 4117:
                    ret = "CLIENT_COMMAND_UPDATE_USER_INFO";
                    break;
                case 16403:
                    ret = "SERVER_COMMAND_USER_CHAT";
                    break;
                case 16386:
                    ret = "SERVER_COMMAND_LOGIN_ERR";
                    break;
                case 16422:
                    ret = "SERVER_COMMAND_VENUECOSTS";
                    break;
                case 16401:
                    ret = "SERVER_COMMAND_FINAL_GAME";
                    break;
                case 20481:
                    ret = "SERVER_COMMAND_USER_CHANGE_SERVER";
                    break;
                case 16394:
                    ret = "SERVER_COMMAND_DEAL_PREFLOP";
                    break;
                case 0x4040:
                    ret = "SERVER_COMMAND_STANDTIMING";
                    break;
                case 4107:
                    ret = "CLIENT_COMMAND_USER_ADDFRIEND";
                    break;
                case 12290:
                    ret = "SERVER_COMMAND_PACKETVERERR";
                    break;
                case 16439:
                    ret = "SERVER_COMMAND_MTTSNGRANKDATA";
                    break;
                case 28674:
                    ret = "CLIENT_ECHO_CONN";
                    break;
                case 8193:
                    ret = "CLIENT_CMD_CONNECT_GAMESERVER_S";
                    break;
                case 16437:
                    ret = "SERVER_COMMAND_USERUPDATAEXP";
                    break;
                case 16438:
                    ret = "SERVER_COMMAND_SHOWDEALPREFLOPCARD";
                    break;
                case 16410:
                    ret = "SERVER_COMMAND_SYSMSG";
                    break;
                case 4110:
                    ret = "CLIENT_COMMAND_USER_KICKUSER_REQUEST";
                    break;
                case 16409:
                    ret = "SERVER_COMMAND_TABLECHATHISTORY";
                    break;
                case 16420:
                    ret = "SERVER_COMMAND_STOPSERVER";
                    break;
                case 16427:
                    ret = "SERVER_COMMAND_SNGTALBESTATE";
                    break;
                case 16404:
                    ret = "SERVER_COMMAND_BIND_SUCCESS";
                    break;
                case 4118:
                    ret = "CLIENT_COMMAND_CHANGE_SERVER_USER_LOGIN";
                    break;
                case 258:
                    ret = "CLIENT_COMMAND_CONNECTFAILED";
                    break;
                case 0x1010:
                    ret = "CLIENT_COMMAND_SNGTABLEINFO";
                    break;
                case 16412:
                    ret = "SERVER_COMMAND_SYSTOOTHER";
                    break;
                case 16445:
                    ret = "SERVER_COMMAND_MTTFINAL";
                    break;
                case 4111:
                    ret = "CLIENT_COMMAND_USER_SMALLFEES";
                    break;
                case 4114:
                    ret = "CLIENT_COMMAND_SHOWDEALPREFLOPCARD";
                    break;
                case 16417:
                    ret = "SERVER_COMMAND_USER_KICKUSER_RESPONSE";
                    break;
                case 16396:
                    ret = "SERVER_COMMAND_DEAL_TURN";
                    break;
                case 4099:
                    ret = "CLIENT_COMMAND_SIT_REQUEST";
                    break;
                case 16433:
                    ret = "SERVER_COMMAND_SNGTIMESMALLBLIN";
                    break;
                case 16446:
                    ret = "SERVER_COMMAND_GLODRUSHCHANGEROOM";
                    break;
                case 2049:
                    ret = "CLIENT_CMD_CONNECT_GAMESERVER";
                    break;
                case 8195:
                    ret = "SERVER_CMD_CONNECT_GAMESERVER_FAILED_S";
                    break;
                case 16405:
                    ret = "SERVER_COMMAND_USER_FROMTOCHIPS";
                    break;
                case 16415:
                    ret = "SERVER_COMMAND_USER_ADDFRIEND_SUCCESS";
                    break;
                case 16390:
                    ret = "SERVER_BROADCAST_USER_SIT";
                    break;
                case 16434:
                    ret = "SERVER_COMMAND_LOTTERYBUY";
                    break;
                case 16436:
                    ret = "SERVER_COMMAND_SYSKICKUSER";
                    break;
                case 4105:
                    ret = "CLIENT_COMMAND_USER_NOTICEALL";
                    break;
                case 16451:
                    ret = "SERVER_COMMAND_RANK_ONE_NOTICE";
                    break;
                case 16387:
                    ret = "SERVER_COMMAND_LOGIN_SUCCESS";
                    break;
                case 16389:
                    ret = "SERVER_COMMAND_SIT_FAILED";
                    break;
                case 2306:
                    ret = "SERVER_CMD_CONNECT_GAMESERVER_FAILED";
                    break;
                case 16402:
                    ret = "SERVER_COMMAND_SHOW_PREFLOP";
                    break;
                case 16414:
                    ret = "SERVER_COMMAND_USER_ADDFRIEND";
                    break;
                case 16444:
                    ret = "SERVER_COMMAND_CHANGESERVER";
                    break;
                case 4100:
                    ret = "CLIENT_COMMAND_TABLEINFO_REQUEST";
                    break;
                case 16395:
                    ret = "SERVER_COMMAND_DEAL_FLOP";
                    break;
                case 4103:
                    ret = "CLIENT_COMMAND_USER_FROMTOCHIPS";
                    break;
                case 16399:
                    ret = "SERVER_COMMAND_USER_ACTION";
                    break;
                case 16424:
                    ret = "SERVER_COMMAND_SNGBIND_SUCCESS";
                    break;
                case 16430:
                    ret = "SERVER_COMMAND_SNGALLBIND_SUCCESS";
                    break;
                case 16435:
                    ret = "SERVER_COMMAND_LOTTERYMONEY";
                    break;
                case 16423:
                    ret = "SERVER_COMMAND_SNGLOGIN_SUCCESS";
                    break;
                case 16400:
                    ret = "SERVER_COMMAND_FINAL_ROUND";
                    break;
                case 16388:
                    ret = "SERVER_COMMAND_SIT_SUCCESS";
                    break;
                case 16385:
                    ret = "SERVER_COMMAND_USER_NOT_FOUND";
                    break;
                case 16418:
                    ret = "SERVER_COMMAND_VOTEEND";
                    break;
                case 16393:
                    ret = "SERVER_BROADCAST_GAME_START";
                    break;
                case 16419:
                    ret = "SERVER_COMMAND_KICKUSER_RESPONSE";
                    break;
                case 2305:
                    ret = "SERVER_CMD_CONNECT_GAMESERVER_SUCCESS";
                    break;
                case 16421:
                    ret = "SERVER_COMMAND_USER_SMALLFEES";
                    break;
                case 4097:
                    ret = "CLIENT_COMMAND_LOGIN";
                    break;
                case 8194:
                    ret = "SERVER_CMD_CONNECT_GAMESERVER_SUCCESS_S";
                    break;
                case 4102:
                    ret = "CLIENT_COMMAND_USER_CHAT";
                    break;
                case 16443:
                    ret = "SERVER_COMMAND_MTTSNGTIMESTART";
                    break;
                case 16411:
                    ret = "SERVER_COMMAND_SYSTOUSERCHIPS";
                    break;
                case 16392:
                    ret = "SERVER_COMMAND_TABLEINFO_RESPONSE";
                    break;
                case 16440:
                    ret = "SERVER_COMMAND_MTTSNGUSERRANKINFO";
                    break;
                case 16425:
                    ret = "SERVER_BROADCAST_SNGGAME_START";
                    break;
                case 16442:
                    ret = "SERVER_COMMAND_MTTSNGCHANGETABLE";
                    break;
                case 4115:
                    ret = "CLIENT_COMMAND_MTTSNGRANKDATA";
                    break;
                case 4119:
                    ret = "CLIENT_COMMAND_ROOMINFO_REQUEST";
                    break;
                case 16452:
                    ret = "SERVER_COMMAND_ROOMINFO_RESPONSE";
                    break;
                case 16453:
                    ret = "SERVER_COMMAND_PLAYERINFO_RESPONSE";
                    break;
                default:
                    //throw new Exception("command not know!");
                    ret = string.Format("unknow cmd {0}", cmd);
                    break;
            }

            return ret;
        }

        public static void ParseMessageFile()
        {
            string filename = "sequencedata.xml";
            XmlDocument dom = new XmlDocument();
            dom.Load(filename);

            int unknownPacket = 0;

            XmlNodeList list = dom.SelectSingleNode("pdml").ChildNodes;
            foreach (XmlNode nodePacket in list)
            {
                // 分析一个封包
                XmlNodeList listProto = nodePacket.SelectNodes("proto");
                string srcIP = "", destIP = "";

                foreach (XmlNode nodeProto in listProto)
                {
                    if (nodeProto.Attributes["name"] != null)
                    {
                        string layername = nodeProto.Attributes["name"].Value;
                        
                        if (layername.Equals("ip", StringComparison.OrdinalIgnoreCase))
                        {
                            // 获取IP地址方向
                            XmlNodeList listIPField = nodeProto.SelectNodes("field");

                            foreach (XmlNode nodeField in listIPField)
                            {
                                if (nodeField.Attributes["name"] != null && nodeField.Attributes["show"] != null)
                                {
                                    string ipfield = nodeField.Attributes["name"].Value;
                                    string ipaddress = nodeField.Attributes["show"].Value;

                                    if (ipfield.Equals("ip.src", StringComparison.OrdinalIgnoreCase))
                                    {
                                        srcIP = ipaddress;
                                    }
                                    else if (ipfield.Equals("ip.dst", StringComparison.OrdinalIgnoreCase))
                                    {
                                        destIP = ipaddress;
                                    }
                                }
                            }
                        }
                        else if (layername.Equals("fake-field-wrapper", StringComparison.OrdinalIgnoreCase))
                        {
                            XmlNode datanode = nodeProto.SelectSingleNode("field");

                            if (datanode != null 
                                && datanode.Attributes["name"] != null 
                                && datanode.Attributes["name"].Value.Equals("data", StringComparison.OrdinalIgnoreCase)
                                && datanode.Attributes["value"] != null)
                            {
                                string rawdatastring = datanode.Attributes["value"].Value.ToLower();

                                if (rawdatastring.IndexOf("4943") == 0)
                                {
                                    XmlNode dataraw = datanode.SelectNodes("field")[0];

                                    string bytestring = dataraw.Attributes["show"].Value.ToLower();

                                    string[] arrdata = bytestring.Split(':');

                                    MessagePacket msgPkt = new MessagePacket();
                                    msgPkt.SrcIP = srcIP;
                                    msgPkt.DestIP = destIP;

                                    foreach (string bytevalue in arrdata)
                                    {
                                        char low = bytevalue[1];
                                        char high = bytevalue[0];

                                        int iLow = CharToInt(low);
                                        int iHigh = CharToInt(high);

                                        iHigh = iHigh << 4;
                                        iHigh = iHigh & 0xF0;

                                        iLow = iLow & 0x0F;

                                        byte btAdd = (byte)((byte)iHigh + (byte)iLow);

                                        msgPkt.Data.writeByte(btAdd);
                                    }

                                    listMessage.Add(msgPkt);
                                }
                                else if (rawdatastring.IndexOf("4259") == 4)
                                {
                                    int len = rawdatastring.Length;
                                    int bodylen = len + 2;

                                    int k = 0;
                                }
                                else 
                                {
                                    unknownPacket++;
                                }
                            }
                        }
                    }
                }
            }
        }

        public static void ParseMessageFullcycle()
        {
            // 所有字节整合在一起，然后parse
            string filename = "sequencedata.xml";
            XmlDocument dom = new XmlDocument();
            dom.Load(filename);

            ByteArray totaldata = new ByteArray();
            bool bSkip = true;

            XmlNodeList list = dom.SelectSingleNode("pdml").ChildNodes;
            foreach (XmlNode nodePacket in list)
            {
                // 提取每个封包的数据
                XmlNodeList listProto = nodePacket.SelectNodes("proto");

                foreach (XmlNode nodeProto in listProto)
                {
                    if (nodeProto.Attributes["name"] != null)
                    {
                        string layername = nodeProto.Attributes["name"].Value;

                        if (layername.Equals("fake-field-wrapper", StringComparison.OrdinalIgnoreCase))
                        {
                            XmlNode datanode = nodeProto.SelectSingleNode("field");

                            if (datanode != null
                                && datanode.Attributes["name"] != null
                                && datanode.Attributes["name"].Value.Equals("data", StringComparison.OrdinalIgnoreCase)
                                && datanode.Attributes["value"] != null)
                            {
                                string rawdatastring = datanode.Attributes["value"].Value.ToLower();

                                if (rawdatastring.IndexOf("0110") == 4)
                                {
                                    totaldata.Reset();
                                    bSkip = false;

                                    XmlNode dataraw = datanode.SelectNodes("field")[0];

                                    string bytestring = dataraw.Attributes["show"].Value.ToLower();

                                    string[] arrdata = bytestring.Split(':');

                                    foreach (string bytevalue in arrdata)
                                    {
                                        char low = bytevalue[1];
                                        char high = bytevalue[0];

                                        int iLow = CharToInt(low);
                                        int iHigh = CharToInt(high);

                                        iHigh = iHigh << 4;
                                        iHigh = iHigh & 0xF0;

                                        iLow = iLow & 0x0F;

                                        byte btAdd = (byte)((byte)iHigh + (byte)iLow);

                                        totaldata.writeByte(btAdd);
                                    }
                                }
                                else 
                                {
                                    if (!bSkip)
                                    {
                                        if (rawdatastring.IndexOf("4259") == 4)
                                        {
                                            bSkip = true;
                                        }
                                        else
                                        {
                                            XmlNode dataraw = datanode.SelectNodes("field")[0];

                                            string bytestring = dataraw.Attributes["show"].Value.ToLower();

                                            string[] arrdata = bytestring.Split(':');

                                            foreach (string bytevalue in arrdata)
                                            {
                                                char low = bytevalue[1];
                                                char high = bytevalue[0];

                                                int iLow = CharToInt(low);
                                                int iHigh = CharToInt(high);

                                                iHigh = iHigh << 4;
                                                iHigh = iHigh & 0xF0;

                                                iLow = iLow & 0x0F;

                                                byte btAdd = (byte)((byte)iHigh + (byte)iLow);

                                                totaldata.writeByte(btAdd);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (rawdatastring.IndexOf("4943") == 0)
                                        {
                                            bSkip = false;

                                            XmlNode dataraw = datanode.SelectNodes("field")[0];

                                            string bytestring = dataraw.Attributes["show"].Value.ToLower();

                                            string[] arrdata = bytestring.Split(':');

                                            foreach (string bytevalue in arrdata)
                                            {
                                                char low = bytevalue[1];
                                                char high = bytevalue[0];

                                                int iLow = CharToInt(low);
                                                int iHigh = CharToInt(high);

                                                iHigh = iHigh << 4;
                                                iHigh = iHigh & 0xF0;

                                                iLow = iLow & 0x0F;

                                                byte btAdd = (byte)((byte)iHigh + (byte)iLow);

                                                totaldata.writeByte(btAdd);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // parse data
            int i = 0;
            while (i < totaldata.length)
            {
                int curPos = i;

                byte b1 = totaldata[curPos];
                byte b2 = totaldata[curPos + 1];
                byte b3 = totaldata[curPos + 2];
                byte b4 = totaldata[curPos + 3];

                if (b1 == 0x49 && b2 == 0x43)
                {
                    totaldata.position = (uint)curPos + 6;
                    int len = totaldata.readShort();

                    totaldata.position = (uint)curPos + 2;
                    int cmd = totaldata.readShort();

                    i = curPos + 13 + len;

                    MessagePacket msgPkt = new MessagePacket();
                    msgPkt.Data.writeBytes(totaldata, (uint)curPos, (uint)(13 + len));
                    listMessage.Add(msgPkt);
                }
                else if (b3 == 0x42 && b4 == 0x59)
                {
                    // 
                    throw new Exception("parse error");
                }
                else 
                {
                    throw new Exception("parse error");
                }
            }
        }

        public static void ParseMessageFullcycleWithChat()
        {
            
        }

        public static void InitEncrypt(ByteArray _arg1, ByteArray _arg2)
        {
            _arg1.writeByte(112);
            _arg1.writeByte(47);
            _arg1.writeByte(64);
            _arg1.writeByte(95);
            _arg1.writeByte(68);
            _arg1.writeByte(142);
            _arg1.writeByte(110);
            _arg1.writeByte(69);
            _arg1.writeByte(126);
            _arg1.writeByte(171);
            _arg1.writeByte(44);
            _arg1.writeByte(31);
            _arg1.writeByte(180);
            _arg1.writeByte(172);
            _arg1.writeByte(157);
            _arg1.writeByte(145);
            _arg1.writeByte(13);
            _arg1.writeByte(54);
            _arg1.writeByte(155);
            _arg1.writeByte(11);
            _arg1.writeByte(212);
            _arg1.writeByte(196);
            _arg1.writeByte(57);
            _arg1.writeByte(116);
            _arg1.writeByte(191);
            _arg1.writeByte(35);
            _arg1.writeByte(22);
            _arg1.writeByte(20);
            _arg1.writeByte(6);
            _arg1.writeByte(235);
            _arg1.writeByte(4);
            _arg1.writeByte(62);
            _arg1.writeByte(18);
            _arg1.writeByte(92);
            _arg1.writeByte(139);
            _arg1.writeByte(188);
            _arg1.writeByte(97);
            _arg1.writeByte(99);
            _arg1.writeByte(246);
            _arg1.writeByte(165);
            _arg1.writeByte(225);
            _arg1.writeByte(101);
            _arg1.writeByte(216);
            _arg1.writeByte(245);
            _arg1.writeByte(90);
            _arg1.writeByte(7);
            _arg1.writeByte(240);
            _arg1.writeByte(19);
            _arg1.writeByte(242);
            _arg1.writeByte(32);
            _arg1.writeByte(107);
            _arg1.writeByte(74);
            _arg1.writeByte(36);
            _arg1.writeByte(89);
            _arg1.writeByte(137);
            _arg1.writeByte(100);
            _arg1.writeByte(215);
            _arg1.writeByte(66);
            _arg1.writeByte(106);
            _arg1.writeByte(94);
            _arg1.writeByte(61);
            _arg1.writeByte(10);
            _arg1.writeByte(119);
            _arg1.writeByte(224);
            _arg1.writeByte(128);
            _arg1.writeByte(39);
            _arg1.writeByte(184);
            _arg1.writeByte(197);
            _arg1.writeByte(140);
            _arg1.writeByte(14);
            _arg1.writeByte(250);
            _arg1.writeByte(138);
            _arg1.writeByte(213);
            _arg1.writeByte(41);
            _arg1.writeByte(86);
            _arg1.writeByte(87);
            _arg1.writeByte(108);
            _arg1.writeByte(83);
            _arg1.writeByte(103);
            _arg1.writeByte(65);
            _arg1.writeByte(232);
            _arg1.writeByte(0);
            _arg1.writeByte(26);
            _arg1.writeByte(206);
            _arg1.writeByte(134);
            _arg1.writeByte(131);
            _arg1.writeByte(176);
            _arg1.writeByte(34);
            _arg1.writeByte(40);
            _arg1.writeByte(77);
            _arg1.writeByte(63);
            _arg1.writeByte(38);
            _arg1.writeByte(70);
            _arg1.writeByte(79);
            _arg1.writeByte(111);
            _arg1.writeByte(43);
            _arg1.writeByte(114);
            _arg1.writeByte(58);
            _arg1.writeByte(241);
            _arg1.writeByte(141);
            _arg1.writeByte(151);
            _arg1.writeByte(149);
            _arg1.writeByte(73);
            _arg1.writeByte(132);
            _arg1.writeByte(229);
            _arg1.writeByte(227);
            _arg1.writeByte(121);
            _arg1.writeByte(143);
            _arg1.writeByte(81);
            _arg1.writeByte(16);
            _arg1.writeByte(168);
            _arg1.writeByte(130);
            _arg1.writeByte(198);
            _arg1.writeByte(221);
            _arg1.writeByte(0xFF);
            _arg1.writeByte(252);
            _arg1.writeByte(228);
            _arg1.writeByte(207);
            _arg1.writeByte(179);
            _arg1.writeByte(9);
            _arg1.writeByte(93);
            _arg1.writeByte(234);
            _arg1.writeByte(156);
            _arg1.writeByte(52);
            _arg1.writeByte(249);
            _arg1.writeByte(23);
            _arg1.writeByte(159);
            _arg1.writeByte(218);
            _arg1.writeByte(135);
            _arg1.writeByte(248);
            _arg1.writeByte(21);
            _arg1.writeByte(5);
            _arg1.writeByte(60);
            _arg1.writeByte(211);
            _arg1.writeByte(164);
            _arg1.writeByte(133);
            _arg1.writeByte(46);
            _arg1.writeByte(251);
            _arg1.writeByte(238);
            _arg1.writeByte(71);
            _arg1.writeByte(59);
            _arg1.writeByte(239);
            _arg1.writeByte(55);
            _arg1.writeByte(127);
            _arg1.writeByte(147);
            _arg1.writeByte(175);
            _arg1.writeByte(105);
            _arg1.writeByte(12);
            _arg1.writeByte(113);
            _arg1.writeByte(49);
            _arg1.writeByte(222);
            _arg1.writeByte(33);
            _arg1.writeByte(117);
            _arg1.writeByte(160);
            _arg1.writeByte(170);
            _arg1.writeByte(186);
            _arg1.writeByte(124);
            _arg1.writeByte(56);
            _arg1.writeByte(2);
            _arg1.writeByte(183);
            _arg1.writeByte(129);
            _arg1.writeByte(1);
            _arg1.writeByte(253);
            _arg1.writeByte(231);
            _arg1.writeByte(29);
            _arg1.writeByte(204);
            _arg1.writeByte(205);
            _arg1.writeByte(189);
            _arg1.writeByte(27);
            _arg1.writeByte(122);
            _arg1.writeByte(42);
            _arg1.writeByte(173);
            _arg1.writeByte(102);
            _arg1.writeByte(190);
            _arg1.writeByte(85);
            _arg1.writeByte(51);
            _arg1.writeByte(3);
            _arg1.writeByte(219);
            _arg1.writeByte(136);
            _arg1.writeByte(178);
            _arg1.writeByte(30);
            _arg1.writeByte(78);
            _arg1.writeByte(185);
            _arg1.writeByte(230);
            _arg1.writeByte(194);
            _arg1.writeByte(247);
            _arg1.writeByte(203);
            _arg1.writeByte(125);
            _arg1.writeByte(201);
            _arg1.writeByte(98);
            _arg1.writeByte(195);
            _arg1.writeByte(166);
            _arg1.writeByte(220);
            _arg1.writeByte(167);
            _arg1.writeByte(80);
            _arg1.writeByte(181);
            _arg1.writeByte(75);
            _arg1.writeByte(148);
            _arg1.writeByte(192);
            _arg1.writeByte(146);
            _arg1.writeByte(76);
            _arg1.writeByte(17);
            _arg1.writeByte(91);
            _arg1.writeByte(120);
            _arg1.writeByte(217);
            _arg1.writeByte(177);
            _arg1.writeByte(237);
            _arg1.writeByte(25);
            _arg1.writeByte(233);
            _arg1.writeByte(161);
            _arg1.writeByte(28);
            _arg1.writeByte(182);
            _arg1.writeByte(50);
            _arg1.writeByte(153);
            _arg1.writeByte(163);
            _arg1.writeByte(118);
            _arg1.writeByte(158);
            _arg1.writeByte(123);
            _arg1.writeByte(109);
            _arg1.writeByte(154);
            _arg1.writeByte(48);
            _arg1.writeByte(214);
            _arg1.writeByte(169);
            _arg1.writeByte(37);
            _arg1.writeByte(199);
            _arg1.writeByte(174);
            _arg1.writeByte(150);
            _arg1.writeByte(53);
            _arg1.writeByte(208);
            _arg1.writeByte(187);
            _arg1.writeByte(210);
            _arg1.writeByte(200);
            _arg1.writeByte(162);
            _arg1.writeByte(8);
            _arg1.writeByte(243);
            _arg1.writeByte(209);
            _arg1.writeByte(115);
            _arg1.writeByte(244);
            _arg1.writeByte(72);
            _arg1.writeByte(45);
            _arg1.writeByte(144);
            _arg1.writeByte(202);
            _arg1.writeByte(226);
            _arg1.writeByte(88);
            _arg1.writeByte(193);
            _arg1.writeByte(24);
            _arg1.writeByte(82);
            _arg1.writeByte(254);
            _arg1.writeByte(223);
            _arg1.writeByte(104);
            _arg1.writeByte(152);
            _arg1.writeByte(84);
            _arg1.writeByte(236);
            _arg1.writeByte(96);
            _arg1.writeByte(67);
            _arg1.writeByte(15);
            _arg2.writeByte(81);
            _arg2.writeByte(161);
            _arg2.writeByte(158);
            _arg2.writeByte(176);
            _arg2.writeByte(30);
            _arg2.writeByte(131);
            _arg2.writeByte(28);
            _arg2.writeByte(45);
            _arg2.writeByte(233);
            _arg2.writeByte(119);
            _arg2.writeByte(61);
            _arg2.writeByte(19);
            _arg2.writeByte(147);
            _arg2.writeByte(16);
            _arg2.writeByte(69);
            _arg2.writeByte(0xFF);
            _arg2.writeByte(109);
            _arg2.writeByte(201);
            _arg2.writeByte(32);
            _arg2.writeByte(47);
            _arg2.writeByte(27);
            _arg2.writeByte(130);
            _arg2.writeByte(26);
            _arg2.writeByte(125);
            _arg2.writeByte(245);
            _arg2.writeByte(207);
            _arg2.writeByte(82);
            _arg2.writeByte(168);
            _arg2.writeByte(210);
            _arg2.writeByte(164);
            _arg2.writeByte(180);
            _arg2.writeByte(11);
            _arg2.writeByte(49);
            _arg2.writeByte(151);
            _arg2.writeByte(87);
            _arg2.writeByte(25);
            _arg2.writeByte(52);
            _arg2.writeByte(223);
            _arg2.writeByte(91);
            _arg2.writeByte(65);
            _arg2.writeByte(88);
            _arg2.writeByte(73);
            _arg2.writeByte(170);
            _arg2.writeByte(95);
            _arg2.writeByte(10);
            _arg2.writeByte(239);
            _arg2.writeByte(136);
            _arg2.writeByte(1);
            _arg2.writeByte(220);
            _arg2.writeByte(149);
            _arg2.writeByte(212);
            _arg2.writeByte(175);
            _arg2.writeByte(123);
            _arg2.writeByte(227);
            _arg2.writeByte(17);
            _arg2.writeByte(142);
            _arg2.writeByte(157);
            _arg2.writeByte(22);
            _arg2.writeByte(97);
            _arg2.writeByte(140);
            _arg2.writeByte(132);
            _arg2.writeByte(60);
            _arg2.writeByte(31);
            _arg2.writeByte(90);
            _arg2.writeByte(2);
            _arg2.writeByte(79);
            _arg2.writeByte(57);
            _arg2.writeByte(254);
            _arg2.writeByte(4);
            _arg2.writeByte(7);
            _arg2.writeByte(92);
            _arg2.writeByte(139);
            _arg2.writeByte(238);
            _arg2.writeByte(102);
            _arg2.writeByte(51);
            _arg2.writeByte(196);
            _arg2.writeByte(200);
            _arg2.writeByte(89);
            _arg2.writeByte(181);
            _arg2.writeByte(93);
            _arg2.writeByte(194);
            _arg2.writeByte(108);
            _arg2.writeByte(246);
            _arg2.writeByte(77);
            _arg2.writeByte(251);
            _arg2.writeByte(174);
            _arg2.writeByte(74);
            _arg2.writeByte(75);
            _arg2.writeByte(243);
            _arg2.writeByte(53);
            _arg2.writeByte(44);
            _arg2.writeByte(202);
            _arg2.writeByte(33);
            _arg2.writeByte(120);
            _arg2.writeByte(59);
            _arg2.writeByte(3);
            _arg2.writeByte(253);
            _arg2.writeByte(36);
            _arg2.writeByte(189);
            _arg2.writeByte(37);
            _arg2.writeByte(55);
            _arg2.writeByte(41);
            _arg2.writeByte(172);
            _arg2.writeByte(78);
            _arg2.writeByte(249);
            _arg2.writeByte(146);
            _arg2.writeByte(58);
            _arg2.writeByte(50);
            _arg2.writeByte(76);
            _arg2.writeByte(218);
            _arg2.writeByte(6);
            _arg2.writeByte(94);
            _arg2.writeByte(0);
            _arg2.writeByte(148);
            _arg2.writeByte(96);
            _arg2.writeByte(236);
            _arg2.writeByte(23);
            _arg2.writeByte(152);
            _arg2.writeByte(215);
            _arg2.writeByte(62);
            _arg2.writeByte(203);
            _arg2.writeByte(106);
            _arg2.writeByte(169);
            _arg2.writeByte(217);
            _arg2.writeByte(156);
            _arg2.writeByte(187);
            _arg2.writeByte(8);
            _arg2.writeByte(143);
            _arg2.writeByte(64);
            _arg2.writeByte(160);
            _arg2.writeByte(111);
            _arg2.writeByte(85);
            _arg2.writeByte(103);
            _arg2.writeByte(135);
            _arg2.writeByte(84);
            _arg2.writeByte(128);
            _arg2.writeByte(178);
            _arg2.writeByte(54);
            _arg2.writeByte(71);
            _arg2.writeByte(34);
            _arg2.writeByte(68);
            _arg2.writeByte(99);
            _arg2.writeByte(5);
            _arg2.writeByte(107);
            _arg2.writeByte(240);
            _arg2.writeByte(15);
            _arg2.writeByte(199);
            _arg2.writeByte(144);
            _arg2.writeByte(197);
            _arg2.writeByte(101);
            _arg2.writeByte(226);
            _arg2.writeByte(100);
            _arg2.writeByte(250);
            _arg2.writeByte(213);
            _arg2.writeByte(219);
            _arg2.writeByte(18);
            _arg2.writeByte(122);
            _arg2.writeByte(14);
            _arg2.writeByte(216);
            _arg2.writeByte(126);
            _arg2.writeByte(153);
            _arg2.writeByte(209);
            _arg2.writeByte(232);
            _arg2.writeByte(214);
            _arg2.writeByte(134);
            _arg2.writeByte(39);
            _arg2.writeByte(191);
            _arg2.writeByte(193);
            _arg2.writeByte(110);
            _arg2.writeByte(222);
            _arg2.writeByte(154);
            _arg2.writeByte(9);
            _arg2.writeByte(13);
            _arg2.writeByte(171);
            _arg2.writeByte(225);
            _arg2.writeByte(145);
            _arg2.writeByte(86);
            _arg2.writeByte(205);
            _arg2.writeByte(179);
            _arg2.writeByte(118);
            _arg2.writeByte(12);
            _arg2.writeByte(195);
            _arg2.writeByte(211);
            _arg2.writeByte(159);
            _arg2.writeByte(66);
            _arg2.writeByte(182);
            _arg2.writeByte(155);
            _arg2.writeByte(229);
            _arg2.writeByte(35);
            _arg2.writeByte(167);
            _arg2.writeByte(173);
            _arg2.writeByte(24);
            _arg2.writeByte(198);
            _arg2.writeByte(244);
            _arg2.writeByte(184);
            _arg2.writeByte(190);
            _arg2.writeByte(21);
            _arg2.writeByte(67);
            _arg2.writeByte(112);
            _arg2.writeByte(224);
            _arg2.writeByte(231);
            _arg2.writeByte(188);
            _arg2.writeByte(241);
            _arg2.writeByte(186);
            _arg2.writeByte(165);
            _arg2.writeByte(166);
            _arg2.writeByte(83);
            _arg2.writeByte(117);
            _arg2.writeByte(228);
            _arg2.writeByte(235);
            _arg2.writeByte(230);
            _arg2.writeByte(133);
            _arg2.writeByte(20);
            _arg2.writeByte(72);
            _arg2.writeByte(221);
            _arg2.writeByte(56);
            _arg2.writeByte(42);
            _arg2.writeByte(204);
            _arg2.writeByte(127);
            _arg2.writeByte(177);
            _arg2.writeByte(192);
            _arg2.writeByte(113);
            _arg2.writeByte(150);
            _arg2.writeByte(248);
            _arg2.writeByte(63);
            _arg2.writeByte(40);
            _arg2.writeByte(242);
            _arg2.writeByte(105);
            _arg2.writeByte(116);
            _arg2.writeByte(104);
            _arg2.writeByte(183);
            _arg2.writeByte(163);
            _arg2.writeByte(80);
            _arg2.writeByte(208);
            _arg2.writeByte(121);
            _arg2.writeByte(29);
            _arg2.writeByte(252);
            _arg2.writeByte(206);
            _arg2.writeByte(138);
            _arg2.writeByte(141);
            _arg2.writeByte(46);
            _arg2.writeByte(98);
            _arg2.writeByte(48);
            _arg2.writeByte(234);
            _arg2.writeByte(237);
            _arg2.writeByte(43);
            _arg2.writeByte(38);
            _arg2.writeByte(185);
            _arg2.writeByte(129);
            _arg2.writeByte(124);
            _arg2.writeByte(70);
            _arg2.writeByte(137);
            _arg2.writeByte(115);
            _arg2.writeByte(162);
            _arg2.writeByte(247);
            _arg2.writeByte(114);
        }

        public static byte MapRecvByte(int _arg1, ByteArray _arg2)
        {
            return (_arg2[_arg1]);
        }

        public static int CrevasseBuffer(ByteArray packet, int startPos, int totalLength, int enCode, ByteArray mapArray)
        {
            int pos = startPos;
            while (pos < totalLength)
            {
                packet[pos] = MapRecvByte(packet[pos], mapArray);
                enCode = (enCode + packet[pos]);
                // _arg4;  ???
                enCode = (enCode / 0x0100);
                // _arg4;  ???
                pos++;
            };
            if (enCode != 0)
            {
                return -1;
            };

            return totalLength;
        }

        public static void S_LoginSuccess(ByteArray data, StreamWriter sw)
        {
            //int _local1;
            //int _local2;
            //Int64 _local3;
            //Int64 _local4;
            //string _local5;
            //Int64 _local6;
            //int _local7;
            //_mySokcet.readbegin();            
            //_local1 = _mySokcet.getsubver();
            //_local2 = _mySokcet.readInt();               // smaillBlind
            //if (_local1 == SERVER_SUBPACKET_VER2)
            //{
            //    _local3 = _mySokcet.readInt64();        // buyMinChips
            //    _local4 = _mySokcet.readInt64();        // buyMaxChips
            //}
            //else
            //{
            //    _local3 = _mySokcet.readInt();
            //    _local4 = _mySokcet.readInt();
            //};
            //_local5 = _mySokcet.readString();          // room name
            //_local6 = _mySokcet.readInt64();           // selfUserData.coin
            //_local7 = _mySokcet.readInt();             // chipintime
            // _gameProceess.ProcessLoginSuccess(_local5, _local2, _local3, _local4, _local6, _local7);
            

            data.position = 13;

            int smallBlind = data.readInt();
            uint low = data.readUnsignedInt();
            int high = data.readInt();
            Int64 buyMinChips = ((high * (long)Math.Pow(2, 32)) + low);
            sw.WriteLine("  buyMinChips : {0}", buyMinChips);

            low = data.readUnsignedInt();
            high = data.readInt();
            Int64 buyMaxChips = ((high * (long)Math.Pow(2, 32)) + low);
            sw.WriteLine("  buyMaxChips : {0}", buyMaxChips);

            uint len = data.readUnsignedInt();
            string roomname = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  roomname : {0}", roomname);

            low = data.readUnsignedInt();
            high = data.readInt();
            Int64 usrCoin = ((high * (long)Math.Pow(2, 32)) + low);
            sw.WriteLine("  usrCoin : {0}", usrCoin);
        }

        // SendLogin(_local2.id, _local1.mid, SelfData.instance.userkey, _local1.userName, _local1.imgUrl, _local1.level.toString(), _local1.userOther, _local1.gift);
        public static void C_Login(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.writeBegin(CLIENT_COMMAND_LOGIN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            //_mySokcet.writeInt(_arg1);                       // room id
            //_mySokcet.writeInt(_arg2);                       // mid
            //_mySokcet.writeString(((_arg3) ? _arg3 : ""));   // userkey
            //_mySokcet.writeString(((_arg4) ? _arg4 : ""));   // userName
            //_mySokcet.writeString(((_arg5) ? _arg5 : ""));   // imgUrl
            //_mySokcet.writeString(((_arg6) ? _arg6 : ""));   // level
            //_mySokcet.writeString(((_arg7) ? _arg7 : ""));   // userOther
            //_mySokcet.writeString(((_arg8) ? _arg8 : ""));   // gift
            //_mySokcet.writeEnd();
            //_mySokcet.sendcmd();

            data.position = 13;

            int roomID = data.readInt();
            int mid = data.readInt();
            sw.WriteLine("  mid : {0}", mid);

            uint len = data.readUnsignedInt();
            string usrKey = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrKey : {0}", usrKey);

            len = data.readUnsignedInt();
            string usrName = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrName : {0}", usrName);

            len = data.readUnsignedInt();
            string imgUrl = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  imgUrl : {0}", usrName);

            len = data.readUnsignedInt();
            string level = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  level : {0}", level);

            len = data.readUnsignedInt();
            // "{\"gifturl\":\"\",\"sname\":\"\",\"mbig\":\"http://tp3.sinaimg.cn/3560106970/180/0/1\",\"association\":\"北京 东城区\",
            // \"weiboPage\":\"http://weibo.com/3560106970\",\"sngwinCount\":0,\"sngloseCount\":0,\"privacyControl\":\"[0,0]\",
            // \"addGameTime\":\"2013-06-26\",\"platformType\":0,\"bestCardType\":8,\"experience\":152,\"userSkillExp\":59,\"mfcount\":0,
            // \"homePage\":\" http://game.weibo.com/center/user?userId=3560106970\",\"gameCountToday\":0,\"diamond\":[],\"msgCount\":2,\"sitemid\":\"3560106970\",\"vipLevel\":0,\"mactivetime\":\"2013-07-08\",
            // \"sinav\":\"0\",\"sinavreason\":null,\"sinavtype\":\"-1\",\"integral\":65,\"mttTopCount\":\"0\",\"askfor\":0,\"maxWinChips\":774,\"bestCards\":\"[776,520,1032,268,780]\",\"gameCount\":100,\"city\":\"北京 东城区\",\"winCount\":19,\"unid\":111000,\"maxOwnChips\":24641,\"score\":0,\"sitID\":117,\"sexID\":0,\"loseCount\":81,\"showVip\":0,\"sngr1WinCount\":null,\"siteAdmin\":0,\"sngr2WinCount\":null,\"prize\":7,\"sngr3WinCount\":null,\"totalPrize\":0,\"showHelp\":0,\"sngr1LoseCount\":null,\"diamondnew\":[],\"sngr2LoseCount\":null,\"home\":\"\",\"sngr3LoseCount\":null,\"school\":\"\"}\0"
            string usrOther = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrOther : {0}", usrOther);

            len = data.readUnsignedInt();
            string gift = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  gift : {0}", gift);
        }

        public static void S_GameStart(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();     // ProcessUpdataChips ag
            //_local2 = _mySokcet.readInt();
            //_local3 = _mySokcet.readByte();     // GameRoomData.instance.dealer
            //_local4 = _mySokcet.readByte();     // 总人数
            //_local5 = [];
            //_local6 = 0;
            //while (_local6 < _local4)
            //{
            //    _local11 = _mySokcet.readByte();     // seat id 
            //    _local12 = _mySokcet.readInt64();    // seatMoney
            //    _local13 = _mySokcet.readInt64();    // seatChips
            //    _local14 = _mySokcet.readInt64();    // userData.coin
            //    _gameProceess.ProcessUpdataChips(_local11, _local12, _local13, _local2, _local14);
            //    _local5.push(_local11);
            //    _local6++;
            //};
            //_local7 = judgeBlind(_local3, _local5);
            //_local8 = _local7[0];
            //_local9 = _local7[1];
            //_local10 = 0;
            //while (_local10 < _local4)
            //{
            //    _gameProceess.setBlindState(_local5[_local10], _local8, _local9);
            //    _local10++;
            //};
            //_gameProceess.ProcessGameStart();
            //if ((((_local4 >= 2)) && ((_local3 >= 0))))
            //{
            //    _gameProceess.ProcessStartDealCard(_local3);
            //};

            data.position = 13;

            int arg1Byte = data.readByte(); 
            int arg2Int = data.readInt();

            int dealer = data.readByte();
            sw.WriteLine("  dealer : {0}", dealer);

            int Person = data.readByte();
            sw.WriteLine("  Person : {0}", Person);

            List<PersionInfo> pList = new List<PersionInfo>();

            for (int i = 0; i < Person; i++)
            {
                sw.WriteLine("  Person : {0}", i);

                PersionInfo obj = new PersionInfo();

                obj.seatID = data.readByte();
                sw.WriteLine("    seatID : {0}", obj.seatID);

                obj.seatMoney = data.readInt64();
                sw.WriteLine("    seatMoney : {0}", obj.seatMoney);

                obj.seatChips = data.readInt64();
                sw.WriteLine("    seatChips : {0}", obj.seatChips);

                obj.usrCoins = data.readInt64();
                sw.WriteLine("    usrCoins : {0}", obj.usrCoins);

                pList.Add(obj);
            }
        }

        public static string GetDetailedControllCmd(int cmd)
        {
            string ret = string.Empty;

            switch (cmd)
            {
                case 1:
                    ret = "CHIPIN_FOLD";
                    break;
                case 2:
                    ret = "CHIPIN_CHECK";
                    break;
                case 3:
                    ret = "CHIPIN_CALL";
                    break;
                case 4:
                    ret = "CHIPIN_RAISE";
                    break;
                case 5:
                    ret = "CHIPIN_SMALLBLIND";
                    break;
                case 6:
                    ret = "CHIPIN_BIGBLIND";
                    break;
                case 7:
                    ret = "CHIPIN_ALL_IN";
                    break;

            }

            return ret;
        }

        public static void S_UserAction(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:int;
            //var _local3:int;
            //var _local4:Number;
            //var _local5:Number;
            //var _local6:Number;
            //var _local7:Number;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.getsubver();
            //_local2 = _mySokcet.readByte();          // ProcessUserAction arg1  seat ID
            //_local3 = _mySokcet.readByte();          // ProcessUserAction arg2  控制字段 GameConfig.PLAYER_CHIPIN_FOLD等
            //_local4 = 0;
            //if (_local1 == SERVER_SUBPACKET_VER2)
            //{
            //    _local4 = _mySokcet.readInt64();     // ProcessUserAction arg3
            //}
            //else
            //{
            //    _local4 = _mySokcet.readInt();
            //};
            //_local5 = _mySokcet.readInt64();        // ProcessUserAction arg4    seatMoney
            //_local6 = _mySokcet.readInt64();        // ProcessUserAction arg5    seatChips
            //_local7 = _mySokcet.readInt64();        // ProcessUserAction arg6    userData.coin
            //_gameProceess.ProcessUserAction(_local2, _local3, _local4, _local5, _local6, _local7);

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            int controllCmd = data.readByte();
            sw.WriteLine("  Cmd : {0}", GetDetailedControllCmd(controllCmd));

            //public static const CHIPIN_FOLD:int = 1;
            //public static const CHIPIN_CHECK:int = 2;
            //public static const CHIPIN_CALL:int = 3;
            //public static const CHIPIN_RAISE:int = 4;
            //public static const CHIPIN_SMALLBLIND:int = 5;
            //public static const CHIPIN_BIGBLIND:int = 6;
            //public static const CHIPIN_ALL_IN:int = 7;

            uint currentPos = data.position;
            data.position = 5;
            int version = data.readByte();
            data.position = currentPos;

            Int64 arg3Int64 = 0;
            if (version == 1)
            {
                arg3Int64 = data.readInt();
            }
            else 
            {
                arg3Int64 = data.readInt64();
            }

            Int64 seatMoney = data.readInt64();
            sw.WriteLine("  seatMoney : {0}", seatMoney);

            Int64 seatChips = data.readInt64();
            sw.WriteLine("  seatChips : {0}", seatChips);

            Int64 usrCoins = data.readInt64();
            sw.WriteLine("  usrCoins : {0}", usrCoins);
        }

        public static void C_RequestChipin(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.writeBegin(CLIENT_COMMAND_CHIPIN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            //_mySokcet.writeByte(_arg1);  // GameConfig.CHIPIN_CALL or GameConfig.CHIPIN_CHECK ChipInManager.CHIPIN_RAISE
            //_mySokcet.writeInt64(_arg2); // Money
            //_mySokcet.writeString(_arg3); // userkey
            //_mySokcet.writeEnd();
            //_mySokcet.sendcmd();

            data.position = 13;

            int cmd = data.readByte();
            sw.WriteLine("  Chipin Cmd : {0}", GetDetailedControllCmd(cmd));

            Int64 money = data.readInt64();
            sw.WriteLine("  money : {0}", money);

            uint len = data.readUnsignedInt();
            string usrkey = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrkey : {0}", usrkey);
        }

        public static void S_FinalRound(ByteArray data, StreamWriter sw)
        {
            //var _local2:int;
            //var _local3:int;
            //var _local4:Array;
            //var _local6:Number;
            //super.analysis(_arg1);
            //_socket.readbegin();
            //_local2 = _socket.readByte();
            //_local3 = _socket.readByte();
            //_local4 = new Array();
            //var _local5:int;
            //while (_local5 <= _local3)
            //{
            //    _local6 = _socket.readInt64();
            //    _local4.push(_local6);
            //    _local5++;
            //};
            //_data = new Object();
            //_data["ShowCardState"] = _local2;
            //_data["PotSID"] = _local3;
            //_data["potsarray"] = _local4;

            data.position = 13;

            int showcardstate = data.readByte();
            sw.WriteLine("  showcardstate : {0}", showcardstate);

            int potscount = data.readByte();

            for (int i = 0; i < potscount; i++)
            {
                Int64 potsmoney = data.readInt64();
                sw.WriteLine("  potsmoney : {0}", potsmoney);
            }
        }

        public static int GetCardColor(int card)
        {
            return (card - 1) >> 8;
        }

        public static int GetCartValue(int card)
        {
            return card & 0xFF;
        }

        public static void S_FinalGame(ByteArray data, StreamWriter sw)
        {
            // 获取每个人的底牌
            //_mySokcet.readbegin();
            //PotSID = _mySokcet.readByte();
            //PotSmoney = _mySokcet.readInt64();
            //nPlaying = _mySokcet.readByte();
            //size = _mySokcet.readByte();
            //i = 0;
            //while (i < size)
            //{
            //    id = _mySokcet.readByte();
            //    money = _mySokcet.readInt64();
            //    Card1 = _mySokcet.readShort();
            //    Card2 = _mySokcet.readShort();
            //    Type = _mySokcet.readByte();
            //    goodCard1 = _mySokcet.readShort();
            //    goodCard2 = _mySokcet.readShort();
            //    goodCard3 = _mySokcet.readShort();
            //    goodCard4 = _mySokcet.readShort();
            //    goodCard5 = _mySokcet.readShort();
            //    try
            //    {
            //        if (nPlaying < 2)
            //        {
            //            Type = 0;
            //        };
            //        _gameProceess.ProcessMarkPots(PotSID, PotSmoney, nPlaying, id, money, Card1, Card2, Type, goodCard1, goodCard2, goodCard3, goodCard4, goodCard5);
            //    }
            //    catch(err)
            //    {
            //    };
            //    i = (i + 1);
            //};
            //_gameProceess.ProcessPotsMove(nPlaying);

            data.position = 13;

            int PotSID = data.readByte();
            sw.WriteLine("  PotSID : {0}", PotSID);

            Int64 PotSmoney = data.readInt64();
            sw.WriteLine("  PotSmoney : {0}", PotSmoney);

            int nPlaying = data.readByte();
            sw.WriteLine("  nPlaying : {0}", nPlaying);

            int size = data.readByte();
            sw.WriteLine("  size : {0}", size);

            List<FinalRound> list = new List<FinalRound>();

            for (int i = 0; i < size; i++)
            {
                FinalRound obj = new FinalRound();

                obj.seatID = data.readByte();
                sw.WriteLine("  seatID : {0}", obj.seatID);

                obj.money = data.readInt64();
                sw.WriteLine("    money : {0}", obj.money);

                obj.card1 = data.readShort();
                obj.cardc1 = GetCardColor(obj.card1);
                sw.WriteLine("    Card 1 Color : {0}", obj.cardc1);
                obj.cardv1 = GetCartValue(obj.card1);
                sw.WriteLine("    Card 1 Value : {0}", obj.cardv1);

                obj.card2 = data.readShort();
                obj.cardc2 = GetCardColor(obj.card2);
                sw.WriteLine("    Card 2 Color : {0}", obj.cardc2);
                obj.cardv2 = GetCartValue(obj.card2);
                sw.WriteLine("    Card 2 Value : {0}", obj.cardv2);

                obj.type = data.readByte();

                obj.goodcard1 = data.readShort();
                obj.goodcardc1 = GetCardColor(obj.goodcard1);
                sw.WriteLine("    Good Card 1 Color : {0}", obj.goodcardc1);
                obj.goodcardv1 = GetCartValue(obj.goodcard1);
                sw.WriteLine("    Good Card 1 Value : {0}", obj.goodcardv1);

                obj.goodcard2 = data.readShort();
                obj.goodcardc2 = GetCardColor(obj.goodcard2);
                sw.WriteLine("    Good Card 2 Color : {0}", obj.goodcardc2);
                obj.goodcardv2 = GetCartValue(obj.goodcard2);
                sw.WriteLine("    Good Card 2 Value : {0}", obj.goodcardc2);

                obj.goodcard3 = data.readShort();
                obj.goodcardc3 = GetCardColor(obj.goodcard3);
                sw.WriteLine("    Good Card 3 Color : {0}", obj.goodcardc3);
                obj.goodcardv3 = GetCartValue(obj.goodcard3);
                sw.WriteLine("    Good Card 3 Value : {0}", obj.goodcardv3);

                obj.goodcard4 = data.readShort();
                obj.goodcardc4 = GetCardColor(obj.goodcard4);
                sw.WriteLine("    Good Card 4 Color : {0}", obj.goodcardc4);
                obj.goodcardv4 = GetCartValue(obj.goodcard4);
                sw.WriteLine("    Good Card 4 Value : {0}", obj.goodcardv4);

                obj.goodcard5 = data.readShort();
                obj.goodcardc5 = GetCardColor(obj.goodcard5);
                sw.WriteLine("    Good Card 5 Color : {0}", obj.goodcardc5);
                obj.goodcardv5 = GetCartValue(obj.goodcard5);
                sw.WriteLine("    Good Card 5 Value : {0}", obj.goodcardv5);

                list.Add(obj);
            }
        }

        public static void S_UserUpdataExp(ByteArray data, StreamWriter sw)
        {
            //var _local1:String;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readString();
            //_gameProceess.ProcessUserUpdataExp(_local1);

            data.position = 13;

            uint len = data.readUnsignedInt();
            string exp = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  exp : {0}", exp);
        }

        public static void C_SendSitRequset(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.writeBegin(CLIENT_COMMAND_SIT_REQUEST, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            //_mySokcet.writeByte(_arg1);    // seat id
            //_mySokcet.writeInt64(_arg2);   // buy chip
            //_mySokcet.writeInt(_arg3);     // 是否自动购买chip
            //_mySokcet.writeEnd();
            //_mySokcet.sendcmd();

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            Int64 buyChip = data.readInt64();
            sw.WriteLine("  buyChip : {0}", buyChip);

            int isAutoBuy = data.readByte();
            sw.WriteLine("  isAutoBuy : {0}", isAutoBuy);
        }

        public static void S_SitSuccess(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:String;
            //var _local3:Number;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();              // seat ID
            //_local2 = _mySokcet.readString();            // user name
            //_local3 = _mySokcet.readInt64();             // seatMoney, buyMoney
            //_gameProceess.ProcessSitSuccess(_local1, _local2, _local3);

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            uint len = data.readUnsignedInt();
            string usrName = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrName : {0}", usrName);

            Int64 seatMoney = data.readInt64();
            sw.WriteLine("  seatMoney : {0}", seatMoney);
        }

        public static void C_SendUserInfosUpdate(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.writeBegin(CLIENT_COMMAND_UPDATE_USER_INFO, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            //_mySokcet.writeEnd();
            //_mySokcet.sendcmd();
        }

        public static void S_UserSit(ByteArray data, StreamWriter sw)
        {
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();    // seat id
            //_local2 = _mySokcet.readInt();     // userData.mid
            //_local3 = _mySokcet.readInt64();   // userData.coin
            //_local4 = _mySokcet.readString();  // userName 
            //_local5 = _mySokcet.readString();  // imgUrl
            //_local6 = _mySokcet.readString();  // level
            //_local7 = _mySokcet.readString();  // userOther
            //_local8 = _mySokcet.readString();  // gift
            //_local9 = _mySokcet.readInt64();   // seatMoney, bureauMoney
            //_gameProceess.ProcessUserSit(_local1, _local2, _local9, 0, _local4, _local5, _local6, _local7, _local8, 0, _local3, 0);

            // 其他玩家坐下后系统通知的消息
            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            int mid = data.readInt();
            sw.WriteLine("  mid : {0}", mid);

            Int64 usrCoin = data.readInt64();
            sw.WriteLine("  usrCoin : {0}", usrCoin);

            uint len = data.readUnsignedInt();
            string usrName = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrName : {0}", usrName);

            len = data.readUnsignedInt();
            string imgUrl = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  imgUrl : {0}", imgUrl);

            len = data.readUnsignedInt();
            string level = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  level : {0}", level);

            len = data.readUnsignedInt();
            string userOther = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  userOther : {0}", userOther);

            len = data.readUnsignedInt();
            string gift = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  gift : {0}", gift);

            Int64 seatMoney = data.readInt64();
            sw.WriteLine("  seatMoney : {0}", seatMoney);
        }

        public static void S_DealFolp(ByteArray data, StreamWriter sw)
        {
            //var _local1:uint;
            //var _local2:uint;
            //var _local3:uint;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readShort();   // 第一张公共牌
            //_local2 = _mySokcet.readShort();   // 第二张公共牌
            //_local3 = _mySokcet.readShort();   // 第三张公共牌
            //_gameProceess.ProcessDealFlop(_local1, _local2, _local3);

            data.position = 13;

            int card_1 = data.readShort();
            int card_1_color = GetCardColor(card_1);
            sw.WriteLine("  card 1 Color : {0}", card_1_color);
            int card_1_value = GetCartValue(card_1);
            sw.WriteLine("  card 1 Value : {0}", card_1_value);

            int card_2 = data.readShort();
            int card_2_color = GetCardColor(card_2);
            sw.WriteLine("  card 2 Color : {0}", card_2_color);
            int card_2_value = GetCartValue(card_2);
            sw.WriteLine("  card 2 Value : {0}", card_2_value);

            int card_3 = data.readShort();
            int card_3_color = GetCardColor(card_3);
            sw.WriteLine("  card 3 Color : {0}", card_3_color);
            int card_3_value = GetCartValue(card_3);
            sw.WriteLine("  card 3 Value : {0}", card_3_value);
        }

        public static void S_DealPreflop(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:uint;
            //var _local3:uint;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();
            //trace(("DealPreflop:" + _local1));
            //_local2 = _mySokcet.readShort();
            //_local3 = _mySokcet.readShort();
            //_gameProceess.ProcessDealPrefLop(_local1, _local2, _local3);

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            int card_1 = data.readShort();
            int card_1_color = GetCardColor(card_1);
            sw.WriteLine("  card 1 Color : {0}", card_1_color);
            int card_1_value = GetCartValue(card_1);
            sw.WriteLine("  card 1 Value : {0}", card_1_value);


            int card_2 = data.readShort();
            int card_2_color = GetCardColor(card_2);
            sw.WriteLine("  card 2 Color : {0}", card_2_color);
            int card_2_value = GetCartValue(card_2);
            sw.WriteLine("  card 2 Value : {0}", card_2_value);
        }

        public static void S_UserStand(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:String;
            //var _local3:Number;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();      // seat ID
            //_local2 = _mySokcet.readString();    // 
            //_local3 = _mySokcet.readInt64();     // selfUserData.coin 如果是自己站起
            //_gameProceess.ProcessUserStand(_local1, _local2, _local3);

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            uint len = data.readUnsignedInt();
            string usrName = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrName : {0}", usrName);

            Int64 usrCoin = data.readInt64();
            sw.WriteLine("  usrCoin : {0}", usrCoin);
        }

        public static void S_ChipPin(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:Number;
            //var _local3:Number;
            //var _local4:Number;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();      // seat ID
            //_local2 = _mySokcet.readInt64();     // _needCall
            //_local3 = _mySokcet.readInt64();     // _needRaise
            //_local4 = _mySokcet.readInt64();     // _maxRaise
            //_gameProceess.ProcessStartChipin(_local1, _local2, _local3, _local4);

            data.position = 13;

            int seatID = data.readByte();
            sw.WriteLine("  seatID : {0}", seatID);

            Int64 needCall = data.readInt64();
            sw.WriteLine("  needCall : {0}", needCall);

            Int64 needRaise = data.readInt64();
            sw.WriteLine("  needRaise : {0}", needRaise);

            Int64 maxRaise = data.readInt64();
            sw.WriteLine("  maxRaise : {0}", maxRaise);
        }

        public static void S_DealTurn(ByteArray data, StreamWriter sw)
        {
            //var _local1:uint;
            //var _local2:uint;
            //var _local3:uint;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readShort();  // ProcessDealFlop  arg1  publicCarList[0] 公共牌1
            //_local2 = _mySokcet.readShort();  // ProcessDealFlop  arg2  publicCarList[1] 公共牌2
            //_local3 = _mySokcet.readShort();  // ProcessDealFlop  arg3  publicCarList[0] 公共牌3
            //_gameProceess.ProcessDealFlop(_local1, _local2, _local3);

            data.position = 13;

            int card_1 = data.readShort();
            int card_1_color = GetCardColor(card_1);
            sw.WriteLine("  card Turn Color : {0}", card_1_color);
            int card_1_value = GetCartValue(card_1);
            sw.WriteLine("  card Turn Value : {0}", card_1_value);
        }

        public static void S_DealRiver(ByteArray data, StreamWriter sw)
        {
            //var _local1:uint;
            //var _local2:uint;
            //var _local3:uint;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readShort();  // ProcessDealFlop  arg1  publicCarList[0] 公共牌1
            //_local2 = _mySokcet.readShort();  // ProcessDealFlop  arg2  publicCarList[1] 公共牌2
            //_local3 = _mySokcet.readShort();  // ProcessDealFlop  arg3  publicCarList[0] 公共牌3
            //_gameProceess.ProcessDealFlop(_local1, _local2, _local3);

            data.position = 13;

            int card_1 = data.readShort();
            int card_1_color = GetCardColor(card_1);
            sw.WriteLine("  card River Color : {0}", card_1_color);
            int card_1_value = GetCartValue(card_1);
            sw.WriteLine("  card River Value : {0}", card_1_value);
        }

        public static void S_ShowPreflop(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:int;
            //var _local3:int;
            //var _local4:uint;
            //var _local5:uint;
            //var _local6:Boolean;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readByte();
            //_local2 = 0;
            //while (_local2 < _local1)
            //{
            //    _local3 = _mySokcet.readByte();
            //    _local4 = _mySokcet.readShort();
            //    _local5 = _mySokcet.readShort();
            //    _local6 = Boolean(_mySokcet.readByte());
            //    _gameProceess.ProcessAddShowPreflop(_local3, _local4, _local5, _local6);
            //    _local2++;
            //};
            //if (_local1 > 0)
            //{
            //    _gameProceess.ProcessShowPreflop();
            //};

            data.position = 13;
            int count = data.readByte();

            for (int i = 0; i < count; i++)
            {
                int seatID = data.readByte();
                sw.WriteLine("  seatID : {0}", seatID);

                int card_1 = data.readShort();
                int card_1_color = GetCardColor(card_1);
                sw.WriteLine("  card 1 Color : {0}", card_1_color);
                int card_1_value = GetCartValue(card_1);
                sw.WriteLine("  card 1 Value : {0}", card_1_value);


                int card_2 = data.readShort();
                int card_2_color = GetCardColor(card_2);
                sw.WriteLine("  card 2 Color : {0}", card_2_color);
                int card_2_value = GetCartValue(card_2);
                sw.WriteLine("  card 2 Value : {0}", card_2_value);

                int arg4 = data.readByte();
            }
        }

        public static void S_UserLogin(ByteArray data, StreamWriter sw)
        {
            //var list:Array;
            //var uid:* = undefined;
            //var count:int;
            //var i:int;
            //var id:int;
            //var name:String;
            //var count1:int;
            //var j:int;
            //var id1:int;
            //var name1:String;
            //var nChips1:Number;
            //var iconurl1:String;
            //try
            //{
            //    list = new Array();
            //    _mySokcet.readbegin();
            //    count = _mySokcet.readInt();
            //    i = 0;
            //    while (i < count)
            //    {
            //        id = _mySokcet.readInt();
            //        name = _mySokcet.readString();
            //        list[id] = name;
            //        i = (i + 1);
            //    };
            //}
            //catch(e:Error)
            //{
            //    list = new Array();
            //    _mySokcet.readbegin();
            //    count1 = _mySokcet.readInt();
            //    j = 0;
            //    while (j < count)
            //    {
            //        id1 = _mySokcet.readInt();
            //        name1 = _mySokcet.readString();
            //        nChips1 = _mySokcet.readInt64();
            //        iconurl1 = _mySokcet.readString();
            //        list[id1] = name1;
            //        j = (j + 1);
            //    };
            //};
            //for (uid in list)
            //{
            //    _gameProceess.ProcessUserLogin(int(uid), list[uid]);
            //};

            data.position = 13;
            int count = data.readInt();

            for (int i = 0; i < count; i++)
            {
                int usrid = data.readInt();
                sw.WriteLine("  usrid : {0}", usrid);

                uint len = data.readUnsignedInt();
                string usrname = data.readMultiByte(len, "utf-8");
                sw.WriteLine("  usrname : {0}", usrname);
            }
        }

        public static void S_UserLogOut(ByteArray data, StreamWriter sw)
        {
            //var _local1:int;
            //var _local2:String;
            //_mySokcet.readbegin();
            //_local1 = _mySokcet.readInt();
            //_local2 = _mySokcet.readString();
            //_gameProceess.ProcessUserLogOut(_local1, _local2);

            data.position = 13;

            int usrid = data.readInt();
            sw.WriteLine("  usrid : {0}", usrid);

            uint len = data.readUnsignedInt();
            string usrname = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrname : {0}", usrname);
        }

        public static void S_RoomInfoResponse(ByteArray data, StreamWriter sw)
        {
            //_socket.readbegin();
            //_local3 = _socket.readByte(); gamestate 
            //_local4 = _socket.readByte(); GameMaxPlayCount
            //_local5 = _socket.readInt();  GameBid
            //_local6 = _socket.readByte(); Dealer
            //_local7 = _socket.readByte(); size
            //var _local8:int = _socket.readByte();
            //_local9 = new Array();
            //var _local10:int;
            //while (_local10 <= _local8)
            //{
            //    _local2 = _socket.readInt64();
            //    _local9.push(_local2);
            //    _local10++;
            //};
            //_local11 = new Array();
            //if ((((_local3 >= 3)) && ((_local3 <= 5))))
            //{
            //    _local16 = 0;
            //    while (_local16 < _local3)
            //    {
            //        _local11[_local16] = _socket.readShort();
            //        _local16++;
            //    };
            //};
            //_local12 = _socket.readShort();  curChipinID
            //_local13 = 0;
            //var _local14:Number = 0;
            //var _local15:Number = 0;
            //if (_local12 != 0)
            //{
            //    _local13 = _socket.readInt64(); NeedCall
            //    _local14 = _socket.readInt64(); NeedRaise
            //    _local15 = _socket.readInt64(); NeedMaxRaise
            //};

            data.position = 13;

            int gamestate = data.readByte();
            sw.WriteLine("  gamestate : {0}", gamestate);

            int maxplaycount = data.readByte();
            sw.WriteLine("  maxplaycount : {0}", maxplaycount);

            int gamebid = data.readInt();
            sw.WriteLine("  gamebid : {0}", gamebid);

            int dealer = data.readByte();
            sw.WriteLine("  dealer : {0}", dealer);

            int playercount = data.readByte();
            sw.WriteLine("  playercount : {0}", playercount);

            int _local8 = data.readByte();
            for (int i = 0; i < _local8; i++)
            {
                Int64 _local2 = data.readInt64();
            }

            for (int i = 0; i < playercount; i++)
            {
                int card = data.readShort();
                sw.WriteLine("  card : {0}", card & 0xFF);
            }
        }

        public static void S_PlayerInfoResponse(ByteArray data, StreamWriter sw)
        {
            //    _local16 = _mySokcet.readByte();   // usr seat ID
            //    _local17 = _mySokcet.readInt();    // SeatData.userData.mid 
            //    _local18 = _mySokcet.readInt64();  // SeatData.userDatauserData.coin
            //    _local19 = _mySokcet.readString(); // SeatData.userData.userName
            //    _local20 = _mySokcet.readString(); // SeatData.userData.imgUrl
            //    _local21 = _mySokcet.readString(); // SeatData.userData.level
            //    _local22 = _mySokcet.readString(); // SeatDatauserData.userOther
            //    _local23 = _mySokcet.readString(); // SeatDatauserData.gift
            //    _local1 = _mySokcet.readInt64();   // SeatData.seatMoney,SeatData.bureauMoney
            //    _local24 = _mySokcet.readInt64();  // SeatData.seatChips
            //    _local25 = _mySokcet.readByte();   // SeatData.userData.isPlay
            //    _local26 = _mySokcet.readByte();   // SeatData.chipinType

            data.position = 13;

            int seatId = data.readByte();
            sw.WriteLine("  seatId : {0}", seatId);

            int usrmid = data.readInt();
            sw.WriteLine("  usrmid : {0}", usrmid);

            Int64 usrcoin = data.readInt64();
            sw.WriteLine("  usrcoin : {0}", usrcoin);

            uint len = data.readUnsignedInt();
            string usrName = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  usrName : {0}", usrName);

            len = data.readUnsignedInt();
            string imgUrl = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  imgUrl : {0}", imgUrl);

            len = data.readUnsignedInt();
            string level = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  level : {0}", level);

            len = data.readUnsignedInt();
            string userOther = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  userOther : {0}", userOther);

            len = data.readUnsignedInt();
            string gift = data.readMultiByte(len, "utf-8");
            sw.WriteLine("  gift : {0}", gift);

            Int64 bureaMoney = data.readInt64();
            sw.WriteLine("  bureaMoney : {0}", bureaMoney);

            Int64 seatChips = data.readInt64();
            sw.WriteLine("  seatChips : {0}", seatChips);

            int isplay = data.readByte();
            sw.WriteLine("  isplay : {0}", isplay);

            int chipintype = data.readByte();
            sw.WriteLine("  chipintype : {0}", chipintype);
        }

        public static void C_RoomInfoRequest(ByteArray data, StreamWriter sw)
        {
            //    _local16 = _mySokcet.readByte();   // usr seat ID
            //    _local17 = _mySokcet.readInt();    // SeatData.userData.mid 
            //    _local18 = _mySokcet.readInt64();  // SeatData.userDatauserData.coin
            //    _local19 = _mySokcet.readString(); // SeatData.userData.userName
            //    _local20 = _mySokcet.readString(); // SeatData.userData.imgUrl
            //    _local21 = _mySokcet.readString(); // SeatData.userData.level
            //    _local22 = _mySokcet.readString(); // SeatDatauserData.userOther
            //    _local23 = _mySokcet.readString(); // SeatDatauserData.gift
            //    _local1 = _mySokcet.readInt64();   // SeatData.seatMoney,SeatData.bureauMoney
            //    _local24 = _mySokcet.readInt64();  // SeatData.seatChips
            //    _local25 = _mySokcet.readByte();   // SeatData.userData.isPlay
            //    _local26 = _mySokcet.readByte();   // SeatData.chipinType

            data.position = 13;


        }

        public static void ParsePacket(MessagePacket packet, StreamWriter sw)
        {
            byte low = packet.Data[2];
            byte high = packet.Data[3];

            int cmd = high;
            cmd = cmd << 8;
            cmd += low;

            packet.Data.position = 13;

            // 解码
            int enCode = 0;
            CrevasseBuffer(packet.Data, 13, (int)packet.Data.length, enCode, m_RecvByteMap);

            switch (cmd)
            {
                case 4097:
                    // CLIENT_COMMAND_LOGIN
                    C_Login(packet.Data, sw);
                    break;
                case 16387:
                    // SERVER_COMMAND_LOGIN_SUCCESS
                    S_LoginSuccess(packet.Data, sw);
                    break;
                case 16416:
                    // SERVER_COMMAND_VOTEKICKUSER
                    break;
                case 4119:
                    // CLIENT_COMMAND_ROOMINFO_REQUEST
                    C_RoomInfoRequest(packet.Data, sw);
                    break;
                case 16452:
                    // SERVER_COMMAND_ROOMINFO_RESPONSE
                    S_RoomInfoResponse(packet.Data, sw);
                    break;
                case 16453:
                    // SERVER_COMMAND_PLAYERINFO_RESPONSE
                    S_PlayerInfoResponse(packet.Data, sw);
                    break;
                case 16437:
                    // SERVER_COMMAND_USERUPDATAEXP
                    S_UserUpdataExp(packet.Data, sw);
                    break;
                case 16393:
                    // SERVER_BROADCAST_GAME_START
                    S_GameStart(packet.Data, sw);
                    break;
                case 4099:
                    // CLIENT_COMMAND_SIT_REQUEST
                    C_SendSitRequset(packet.Data, sw);
                    break;
                case 16388:
                    // SERVER_COMMAND_SIT_SUCCESS
                    S_SitSuccess(packet.Data, sw);
                    break;
                case 4117:
                    // CLIENT_COMMAND_UPDATE_USER_INFO
                    C_SendUserInfosUpdate(packet.Data, sw);
                    break;
                case 16390:
                    // SERVER_BROADCAST_USER_SIT
                    S_UserSit(packet.Data, sw);
                    break;
                case 16394:
                    // SERVER_COMMAND_DEAL_PREFLOP
                    S_DealPreflop(packet.Data, sw);
                    break;
                case 16391:
                    // SERVER_BROADCAST_USER_STAND
                    S_UserStand(packet.Data, sw);
                    break;
                case 16399:
                    // SERVER_COMMAND_USER_ACTION
                    S_UserAction(packet.Data, sw);
                    break;
                case 4101:
                    // CLIENT_COMMAND_CHIPIN
                    C_RequestChipin(packet.Data, sw);
                    break;
                case 16400:
                    // SERVER_COMMAND_FINAL_ROUND
                    S_FinalRound(packet.Data, sw);
                    break;
                case 16401:
                    // SERVER_COMMAND_FINAL_GAME
                    S_FinalGame(packet.Data, sw);
                    break;
                case 16398:
                    // SERVER_COMMAND_START_CHIPIN
                    S_ChipPin(packet.Data, sw); 
                    break;
                case 16395:
                    // SERVER_COMMAND_DEAL_FLOP
                    S_DealFolp(packet.Data, sw);
                    break;
                case 16402:
                    // SERVER_COMMAND_SHOW_PREFLOP
                    S_ShowPreflop(packet.Data, sw);
                    break;
                case 16396:
                    // SERVER_COMMAND_DEAL_TURN
                    S_DealTurn(packet.Data, sw);
                    break;
                case 16397:
                    // SERVER_COMMAND_DEAL_RIVER
                    S_DealRiver(packet.Data, sw);
                    break;
                case 16431:
                    // SERVER_COMMAND_USERLOGIN
                    S_UserLogin(packet.Data, sw);
                    break;
                case 16432:
                    // SERVER_COMMAND_USERLOGOUT
                    S_UserLogOut(packet.Data, sw);
                    break;
                default:
                    break;
            }
        }

        public static void WriteMsgToFile(List<MessagePacket> listMessage, StreamWriter sw)
        {
            foreach (MessagePacket packet in listMessage)
            {
                byte low = packet.Data[2];
                byte high = packet.Data[3];

                int cmd = high;
                cmd = cmd << 8;
                cmd += low;

                string direction = " from " + packet.SrcIP + " to " + packet.DestIP;

                string strCmd = IntCmdToString(cmd);

                sw.WriteLine("Parse Packet...");

                byte code = packet.Data[8];

                low = packet.Data[9];
                high = packet.Data[10];
                int sequence = high;
                sequence = sequence << 8;
                sequence += low;

                string msg = string.Format("Cmd : {0} {1}, Verify Code : {2}, Sequence : {3}", cmd, strCmd, code, sequence);

                sw.WriteLine(msg);

                ParsePacket(packet, sw);
            }
        }

        public static void ParseMessageSequence()
        {
            string outputfile = @"sequence.txt";

            if (!File.Exists(outputfile))
            {
                using (FileStream fs = File.Create(outputfile))
                {
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        WriteMsgToFile(listMessage, sw);
                    }
                }
            }
            else
            {
                using (FileStream fs = File.OpenWrite(outputfile))
                {
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
                    {
                        WriteMsgToFile(listMessage, sw);
                    }
                }
            } 
        }

        static void Main(string[] args)
        {
            InitEncrypt(m_SendByteMap, m_RecvByteMap);

            ParseMessageFile();
            //ParseMessageFullcycle();
            ParseMessageSequence();
        }
    }
}
